﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Ay.Framework.WPF.Applications;
using Ay.Framework.WPF.Controls;
using Ay.MvcFramework;

namespace Demo.Controls
{
    /// <summary>
    /// MySkinCommonSetWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MySkinCommonSetWindow : AyPopupWindow
    {
        public Action AfterSetSkinMethodOverride;
        private string themeLanguage;

        private bool isSkinSet;
        public MySkinCommonSetWindow(AyPopupWindowLocations windowlocation = AyPopupWindowLocations.Center) : base(windowlocation)
        {
            this.InitializeComponent();
            base.Loaded += new RoutedEventHandler(this.MySkinCommonSetWindow_Loaded);
        }

        private void cancelSkinSet_Click(object sender, RoutedEventArgs e)
        {
            base.BeginCloseAnimation();
        }


        private void gsmhSlider_MouseLeftButtonUpEvent(object sender, MouseButtonEventArgs e)
        {
            base.GaoSiRadius = this.gsmhSlider.Value;
        }


        private void okSkinSet_Click(object sender, RoutedEventArgs e)
        {
            double gaoSiRadius = base.GaoSiRadius;
            ConfigSetting.SetXmlValue("Gaosi", "value", gaoSiRadius.ToString(), "Application", false);
            gaoSiRadius = base.RectangleOpacity1;
            ConfigSetting.SetXmlValue("RecOpa1", "value", gaoSiRadius.ToString(), "Application", false);
            gaoSiRadius = base.RectangleOpacity2;
            ConfigSetting.SetXmlValue("RecOpa2", "value", gaoSiRadius.ToString(), "Application", false);
            gaoSiRadius = base.RectangleOpacity3;
            ConfigSetting.SetXmlValue("RecOpa3", "value", gaoSiRadius.ToString(), "Application", false);
            string selectThemeLanguage = this.cboSelectLanguage.SelectedValue.ToString();
            if (this.themeLanguage != selectThemeLanguage)
            {
                ConfigSetting.SetXmlValue("themeLanguage", "value", selectThemeLanguage, "Application", false);
                LanuageManager.ChangeLanguage(System.Windows.Application.Current);
                AfterSetSkinMethodOverride?.Invoke();
            }
            this.isSkinSet = true;
            base.BeginCloseAnimation();

        }

        protected override void OnClosing(CancelEventArgs e)
        {
            if (!this.isSkinSet)
            {
                base.ReloadColorfulConfig();
            }
            base.OnClosing(e);
        }

        private void MySkinCommonSetWindow_Loaded(object sender, RoutedEventArgs e)
        {
            base.Loaded -= this.MySkinCommonSetWindow_Loaded;
            this.gsmhSlider.MouseLeftButtonUp += this.gsmhSlider_MouseLeftButtonUpEvent;
            base.IsCommonPopupWindow = true;
            base.ReloadColorfulConfig();
            if (!LanuageManager.DisabledLanuage)
            {
                Label label = this.lblan;
                this.cboSelectLanguage.Visibility = Visibility.Visible;
                label.Visibility = Visibility.Visible;
            }
            else
            {
                Label label1 = this.lblan;
                this.cboSelectLanguage.Visibility = Visibility.Collapsed;
                label1.Visibility = Visibility.Collapsed;
            }
            this.themeLanguage = AyCommon.ToObjectString(ConfigSetting.GetXmlValue("themeLanguage", "value", false));
            this.cboSelectLanguage.SelectedValue = this.themeLanguage;
            this.cboSelectLanguage.ItemsSource = GlobalCollection.Lanuages;
            if (AyCommon.ISXP)
            {
                this.gsmhSlider.Value = base.GaoSiRadius;
                this.gsmhSlider.Width = 100;
                this.gsmhVisibility.Visibility = Visibility.Visible;
                this.gsmhSlider.IsEnabled = false;
                this.gsmhLabel.Opacity = 0.5;
                this.gsmhVisibility.ToolTip = "此效果只支持在windows xp以上操作系统上使用";
            }
            this.gsmhSlider.Value = base.GaoSiRadius;
            if (ConfigSetting.GetXmlValue("themeMode", "value", false) != "img")
            {
                this.gsmhSlider.Value = base.GaoSiRadius;
                this.gsmhSlider.Width = 100;
                this.gsmhVisibility.Visibility = Visibility.Visible;
                this.gsmhVisibility.ToolTip = "当前为纯色背景，无需设置";
                this.gsmhSlider.IsEnabled = false;
                this.gsmhLabel.Opacity = 0.5;
            }
        }



    }
}
